package com.clk.portfoy.classlib.portfoy;

import java.util.Date;

import com.clk.portfoy.PortfoyStatics;

public abstract class AbsDeger implements InfDeger {
	private String isim;
	private String grup;
	private int adet = 0;
	private double alisDeger = 0;
	private double anlikDeger = 0;
	private double oncekiDeger = -1;
	private double hedefDeger = 0;
	private double realizeDeger = 0;
	private double changePercentage = 0;
	private Date alisTarihi;
	private Date satisTarihi;
	private Portfoy portfoy;

	// ---------------------------------------------------------------------------------
	public String getIsim() {
		return isim;
	}

	// ---------------------------------------------------------------------------------

	public void setIsim(String isim) {
		this.isim = isim;
	}

	// ---------------------------------------------------------------------------------
	public String getGrup() {
		return grup;
	}

	// ---------------------------------------------------------------------------------
	public void setGrup(String grup) {
		this.grup = grup;
	}

	// ---------------------------------------------------------------------------------
	public int getAdet() {
		return adet;
	}

	// ---------------------------------------------------------------------------------
	public void setAdet(int adet) {
		this.adet = adet;
	}

	// ---------------------------------------------------------------------------------
	public double getAlisDeger() {
		return alisDeger;
	}

	// ---------------------------------------------------------------------------------
	public void setAlisDeger(double alisDeger) {
		this.alisDeger = alisDeger;
	}

	// ---------------------------------------------------------------------------------
	public double getAnlikDeger() {
		return anlikDeger;
	}

	// ---------------------------------------------------------------------------------
	public void setAnlikDeger(double anlikDeger) {
		if (this.anlikDeger != 0) {
			oncekiDeger = this.anlikDeger;
		}
		this.anlikDeger = anlikDeger;
	}

	// ---------------------------------------------------------------------------------
	public double getHedefDeger() {
		return hedefDeger;
	}

	// ---------------------------------------------------------------------------------
	public void setHedefDeger(double hedefDeger) {
		this.hedefDeger = hedefDeger;
	}

	// ---------------------------------------------------------------------------------
	public double getRealizeDeger() {
		return realizeDeger;
	}

	// ---------------------------------------------------------------------------------
	public void setRealizeDeger(double satilanDeger) {
		this.realizeDeger = satilanDeger;
	}

	// ---------------------------------------------------------------------------------
	public double getChangePercentage() {
		return changePercentage;
	}

	// ---------------------------------------------------------------------------------
	public void setChangePercentage(double changePercentage) {
		this.changePercentage = changePercentage;
	}

	// ---------------------------------------------------------------------------------
	public Date getAlisTarihi() {
		return alisTarihi;
	}

	// ---------------------------------------------------------------------------------
	public void setAlisTarihi(Date alisTarihi) {
		this.alisTarihi = alisTarihi;
	}

	// ---------------------------------------------------------------------------------
	public Date getSatisTarihi() {
		return satisTarihi;
	}

	// ---------------------------------------------------------------------------------
	public void setSatisTarihi(Date satisTarihi) {
		this.satisTarihi = satisTarihi;
	}

	// ---------------------------------------------------------------------------------
	public Portfoy getPortfoy() {
		return portfoy;
	}

	// ---------------------------------------------------------------------------------
	public void setPortfoy(Portfoy portfoy) {
		this.portfoy = portfoy;
	}

	// ---------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------

	public String getStrAdet() {
		return PortfoyStatics.getDoubleStr(getAdet());
	}

	// ---------------------------------------------------------------------------------
	public String getStrAnlikDeger() {
		return PortfoyStatics.getDoubleStr(getAnlikDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrTotAnlikDeger() {
		return PortfoyStatics.getDoubleStr(getTotAnlikDeger());// **************************
	}

	// ---------------------------------------------------------------------------------
	public String getStrAlisDeger() {
		return PortfoyStatics.getDoubleStr(getAlisDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrPotKZ() {
		return PortfoyStatics.getDoubleStr(getPotKZ());
	}

	// ---------------------------------------------------------------------------------
	public String getStrPercKZ() {
		return PortfoyStatics.getDoubleStr(getPercKZ());
	}

	// ---------------------------------------------------------------------------------
	public String getStrPortfoyDagilim() {
		return PortfoyStatics.getDoubleStr(getPortfoyDagilim());// ***************
	}

	// ---------------------------------------------------------------------------------
	public String getStrHedefDeger() {
		return PortfoyStatics.getDoubleStr(getHedefDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrTotHedefDeger() {
		return PortfoyStatics.getDoubleStr(getTotHedefDeger());// ***************
	}

	// ---------------------------------------------------------------------------------
	public String getStrHedefPotKZ() {
		return PortfoyStatics.getDoubleStr(getHedefPotKZ());
	}

	// ---------------------------------------------------------------------------------
	public String getStrHedefPercKZ() {
		return PortfoyStatics.getDoubleStr(getHedefPercKZ());
	}

	// ---------------------------------------------------------------------------------
	public String getStrAlisTarihi() {
		return PortfoyStatics.getDateStr(getAlisTarihi());
	}

	// ---------------------------------------------------------------------------------
	public String getStrVade() {
		return "" + getVade();
	}

	// ---------------------------------------------------------------------------------
	public String getStrVadeliBirimDeger() {
		return PortfoyStatics.getDoubleStr(getVadeliBirimDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrVadeliTotDeger() {
		return PortfoyStatics.getDoubleStr(getVadeliTotDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrVsVadeliPotKZ() {
		return PortfoyStatics.getDoubleStr(getVsVadeliPotKZ());
	}

	// ---------------------------------------------------------------------------------
	public String getStrRealizeDeger() {
		return PortfoyStatics.getDoubleStr(getRealizeDeger());
	}

	// ---------------------------------------------------------------------------------
	public String getStrSatisTarihi() {
		return PortfoyStatics.getDateStr(getSatisTarihi());
	}

	// ---------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------
	public double getVsVadeliPercKZ() {
		return 100 * (getVadeliBirimDeger() - alisDeger) / alisDeger;
	}

	// ---------------------------------------------------------------------------------
	public double getVsVadeliPotKZ() {
		return getPotKZ() - getVadeliTotDeger();
	}

	// ---------------------------------------------------------------------------------
	public double getVadeliBirimDeger() {
		long vade = getVade();
		double vadeliDegeri = alisDeger * vade * PortfoyStatics.YILLIKFAIZ_ORANI / 36000;
		return vadeliDegeri;
	}

	// ---------------------------------------------------------------------------------
	public double getVadeliTotDeger() {
		return getVadeliBirimDeger() * getAdet();
	}

	// ---------------------------------------------------------------------------------
	public long getVade() {
		Date endDate = null;
		if (this.getSatisTarihi() != null) {
			endDate = this.getSatisTarihi();
		} else {
			endDate = new Date();
		}

		Date startDate = alisTarihi;

		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		long diffTime = endTime - startTime;
		return diffTime / (1000 * 60 * 60 * 24);
	}

	// ---------------------------------------------------------------------------------
	public double getTotAnlikDeger() {
		return getAdet() * getAnlikDeger();
	}

	// ---------------------------------------------------------------------------------
	public double getPortfoyDagilim() {
		if(this.isRealized()) {
			return 0;
		}
		return this.getTotAnlikDeger() * 100 / portfoy.getAnlikDeger();
	}

	// ---------------------------------------------------------------------------------
	public double getTotHedefDeger() {
		return getAdet() * getHedefDeger();
	}

	// ---------------------------------------------------------------------------------
	public double getPotKZ() {
		if (this.getRealizeDeger() <= 0) {
			return getAdet() * (anlikDeger - getAlisDeger());
		}
		return getAdet() * (this.realizeDeger - getAlisDeger());
	}

	// ---------------------------------------------------------------------------------
	public double getPercKZ() {
		if (this.getRealizeDeger() <= 0) {
			return 100 * (anlikDeger - getAlisDeger()) / getAlisDeger();
		}
		return 100 * (this.realizeDeger - getAlisDeger()) / getAlisDeger();
	}

	// ---------------------------------------------------------------------------------
	public double getHedefPotKZ() {
		return getAdet() * (hedefDeger - getAlisDeger());
	}

	// ---------------------------------------------------------------------------------
	public double getHedefPercKZ() {
		return 100 * (hedefDeger - getAlisDeger()) / getAlisDeger();
	}

	// ---------------------------------------------------------------------------------
	public double[] getAnlikDegerSet() {
		if (this.oncekiDeger == -1) {
			this.oncekiDeger = this.anlikDeger;
		}
		double anlikDegerSet[] = { this.anlikDeger, this.oncekiDeger, this.changePercentage };
		return anlikDegerSet;
	}

	// ---------------------------------------------------------------------------------
	public boolean isRealized() {
		if (this.getRealizeDeger() <= 0) {
			return false;
		}
		return true;
	}

	// ---------------------------------------------------------------------------------
	public boolean isInPortfoy() {
		if (this.isRealized() || this.getAdet() <= 0) {
			return false;
		}
		return true;
	}
	// ---------------------------------------------------------------------------------
}
